﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ZDT.Common
{
    public class Utility
    {
        private static Random rnd = new Random();
        public static int NextRnd(int maxValue)
        {
            return rnd.Next(maxValue);
        }
        public static string NextRnd2(int maxValue)
        {
            return rnd.Next(maxValue).ToString().PadLeft((maxValue - 1).ToString().Length, '0');
        }
        public static string NewName()
        {
            DateTime now=DateTime.Now;
            return string.Format("{0}/{1}{2}", now.ToString("yyyy-MM-dd"), now.ToString("HHmmssfff"), NextRnd2(99999));
        }
        public static string BaseImagePath = "Data/Files/Images/";
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ext"></param>
        /// <returns></returns>
        public static string NewImageFilePath(string ext)
        {
            return BaseImagePath + NewName() + ext;
        }
        public static void CreatedPath(string fileName)
        {
            string path = System.IO.Path.GetDirectoryName(fileName);
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
        }
    }
}
